from ham.menu import Menu,SubMenu,Item
from ham.menu import Menu,SubMenu,Item
from django.core.urlresolvers import reverse
from pacs.models import Task

from django.core.urlresolvers import reverse

def build_menus(request,params):
	m = Menu("PACS")

	if 'task_slug' in params:
		s = SubMenu("This task")
		m.add_sub(s)
		s.add_item(Item("Show",reverse('pacs.views.show_task',None,(),{'task_slug':params['task_slug']})))
		s.add_item(Item("Submit",reverse('pacs.views.add_submission',None,(),{'task_slug':params['task_slug']})))
	if 'contest_id' in params:
		s = SubMenu("This contest")
		m.add_sub(s)
		s.add_item(Item("Show",reverse('pacs.views.show_contest',None,(),{'contest_id':params['contest_id']})))

	s = SubMenu("List")
	m.add_sub(s)
	s.add_item(Item("Contests",reverse('pacs.views.list_contests',None,(),{})))
	s.add_item(Item("Submissions",reverse('pacs.views.list_submissions',None,(),{})))

	if request.user.is_anonymous():
		return [m]

	mparams = {}
	mparams.update(params)
	ma = Menu("PACS Admin")
	s = SubMenu("New")
	ma.add_sub(s)
	s.add_item(Item("Full task",reverse("pacs.views.add_full_task",None,(),{})))
	s.add_item(Item("Contest",reverse("pacs.views.add_contest",None,(),{})))
	if 'task_slug' in mparams:
		s = SubMenu("This task")
		ma.add_sub(s)
		s.add_item(Item("Add goal",reverse('pacs.views.add_goal',None,(),{'task_slug':mparams['task_slug']})))
		mparams['problem_id'] = Task.objects.get(slug=mparams['task_slug']).problem.id
	if 'problem_id' in mparams:
		s = SubMenu("This Problem")
		ma.add_sub(s)
		s.add_item(Item("Add test",reverse('pacs.views.add_test',None,(),{'problem_id':mparams['problem_id']})))
	if 'contest_id' in mparams:
		s = SubMenu("This contest")
		ma.add_sub(s)
	return [m,ma]
